@memorysmithapp/markdown-renderer 0.12.1 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/ContentsBlock.d.ts +82 -0
- package/dist/ContentsBlock.js +162 -0
- package/dist/DataTable.js +31 -4
- package/dist/InPageAnchor.d.ts +20 -0
- package/dist/InPageAnchor.js +35 -0
- package/dist/Markdown.d.ts +7 -1
- package/dist/Markdown.js +48 -31
- package/dist/NoteBody.js +107 -28
- package/dist/PropertiesBlock.d.ts +54 -3
- package/dist/PropertiesBlock.js +91 -5
- package/dist/Transclusion.js +4 -1
- package/dist/appendices.d.ts +30 -0
- package/dist/appendices.js +11 -4
- package/dist/contents.d.ts +92 -0
- package/dist/contents.js +224 -0
- package/dist/diagnose.d.ts +3 -1
- package/dist/diagnose.js +25 -0
- package/dist/edit/ContentsDialog.d.ts +39 -0
- package/dist/edit/ContentsDialog.js +126 -0
- package/dist/edit/NoteEditor.js +56 -4
- package/dist/edit/PropertiesDialog.d.ts +42 -0
- package/dist/edit/PropertiesDialog.js +103 -0
- package/dist/edit/StyleDialog.js +5 -3
- package/dist/edit/blocks.d.ts +29 -0
- package/dist/edit/blocks.js +100 -3
- package/dist/edit/contents.d.ts +30 -0
- package/dist/edit/contents.js +76 -0
- package/dist/edit/live.js +72 -2
- package/dist/edit/properties.d.ts +26 -0
- package/dist/edit/properties.js +60 -0
- package/dist/host.d.ts +24 -0
- package/dist/host.js +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/kept-files.d.ts +11 -0
- package/dist/kept-files.js +49 -0
- package/dist/note-style.d.ts +9 -1
- package/dist/note-style.js +4 -2
- package/dist/outline.d.ts +227 -0
- package/dist/outline.js +366 -0
- package/dist/properties-block.d.ts +62 -0
- package/dist/properties-block.js +175 -0
- package/dist/slots.js +11 -2
- package/dist/strings.d.ts +60 -0
- package/dist/strings.js +43 -1
- package/dist/table-block.d.ts +13 -1
- package/dist/table-block.js +2 -1
- package/dist/theme.d.ts +19 -0
- package/package.json +4 -2
- package/structure.css +54 -0
- package/theme-default.css +56 -0
package/README.md
CHANGED
|
@@ -26,7 +26,9 @@ import 'katex/dist/katex.min.css';
|
|
|
26
26
|
loadNoteAt={(address) => fetchTheNoteAt(address)} // …or another note of that name, told apart by address
|
|
27
27
|
queryTable={(request) => queryYourTable(request)} // the rows a ```table block asks for: one page, the count, the total
|
|
28
28
|
openTableRow={(view) => showInYourDialog(view)} // a row clicked, whole: its columns and each value as drawn
|
|
29
|
-
noteStyle={{ font: 'serif', text: 'justify' }}
|
|
29
|
+
noteStyle={{ font: 'serif', text: 'justify', numbering: 'decimal' }} // the notebook's style: face, alignment of headings, text and tables, and the headings numbered
|
|
30
|
+
contents={{ print: { place: 'start', headings: null } }} // the notebook's contents, for a note with no ```contents block
|
|
31
|
+
properties={{ print: { place: 'end' } }} // how the notebook draws a note's properties, for a note with no ```properties block
|
|
30
32
|
writable
|
|
31
33
|
onToggleTask={(ordinal) => save(toggleTaskAt(latest(), ordinal))} // a promise locks the item under "Updating…" until it settles
|
|
32
34
|
theme="dark"
|
|
@@ -34,7 +36,7 @@ import 'katex/dist/katex.min.css';
|
|
|
34
36
|
/>;
|
|
35
37
|
```
|
|
36
38
|
|
|
37
|
-
Every prop is optional, and every default is the safe one: with no `resolve` every link is pending, with no `keeps` no embed reaches a file. A note comes before a file of the same name, and an embed never reaches the note it is written in: give `noteAddress` for a note you keep, and leave it out for a guidance, a template or a draft, which excludes nothing. A file `fileOf` describes is drawn by its media type, never its name: an image, an audio or a video player, and anything else a card with its type, size, description, *Open* where a browser shows it and *Download*; give `renderAttachment` instead to draw files yourself. A `table` block is drawn as its table through `queryTable`: it hands you the table, the columns, the filter as written, the order, the page and its size and the column to sum, you run the filter and answer the table's columns with their kinds, the page's rows — a number as its digits, so none is rounded — the row count, the total and when you read them; `runTableQuery` answers from rows you hold in memory. On the screen a cell holds one line, the columns keep their widths as the pages turn and the footer its place, and a click on a row, or Enter, shows it whole: in your own dialog through `openTableRow`, else in a native `<dialog>`; the footer says which rows of how many it shows, in `strings.tableShowing`, with Previous and Next, which the `--markdown-pager-*` properties style as your own buttons. A reader sorts by a header for themselves, which asks you again; a block that cannot be answered says why in its place; without `queryTable` the block is a code block. To print, set `printing`, wait until no `[aria-busy="true"]` is left under the note, then print: every block has then asked for every row, and carries its header on each page, its total and a line saying what was read and when. A print command does not wait for an answer, so a note printed with no `printing` carries the page each table was on. Set `tablesAsAppendices` beside `printing` and every table of the note, a `table` block or a Markdown table, prints as an appendix at its end, titled in `strings.tableAppendix`, with a link in `strings.tableAppendixReference` in its place; each appendix is a `section.table-appendix` whose id the link names, so `target-counter()` can number its page and a named `page:` can turn it. In edit mode, `renderLink`, `renderAttachment` and a theme's slots may be drawn in a root of their own, outside your React tree, so what they return must not read your context: a router's `<Link>` throws there, and the block shows its Markdown under a notice instead. The stylesheet styles nothing outside `.markdown`. The faces of the default theme are Inter and Space Grotesk, which the page loads.
|
|
39
|
+
Every prop is optional, and every default is the safe one: with no `resolve` every link is pending, with no `keeps` no embed reaches a file. A note comes before a file of the same name, and an embed never reaches the note it is written in: give `noteAddress` for a note you keep, and leave it out for a guidance, a template or a draft, which excludes nothing. A file `fileOf` describes is drawn by its media type, never its name: an image, an audio or a video player, and anything else a card with its type, size, description, *Open* where a browser shows it and *Download*; give `renderAttachment` instead to draw files yourself. A `table` block is drawn as its table through `queryTable`: it hands you the table, the columns, the filter as written, the order, the page and its size and the column to sum, you run the filter and answer the table's columns with their kinds, the page's rows — a number as its digits, so none is rounded — the row count, the total and when you read them; `runTableQuery` answers from rows you hold in memory. On the screen a cell holds one line, the columns keep their widths as the pages turn and the footer its place, and a click on a row, or Enter, shows it whole: in your own dialog through `openTableRow`, else in a native `<dialog>`; a page may also answer `links`, where each of its rows leads, beside `rows`, and `linkColumn`: that column's cell, when drawn, else the first's, is a link drawn as the note's links are, which a click follows without opening the row; the footer says which rows of how many it shows, in `strings.tableShowing`, with Previous and Next, which the `--markdown-pager-*` properties style as your own buttons. A reader sorts by a header for themselves, which asks you again; a block that cannot be answered says why in its place; without `queryTable` the block is a code block. To print, set `printing`, wait until no `[aria-busy="true"]` is left under the note, then print: every block has then asked for every row, and carries its header on each page, its total and a line saying what was read and when. A print command does not wait for an answer, so a note printed with no `printing` carries the page each table was on. Set `tablesAsAppendices` beside `printing` and every table of the note, a `table` block or a Markdown table, prints as an appendix at its end, titled in `strings.tableAppendix`, with a link in `strings.tableAppendixReference` in its place; each appendix is a `section.table-appendix` whose id the link names, so `target-counter()` can number its page and a named `page:` can turn it. In edit mode, `renderLink`, `renderAttachment` and a theme's slots may be drawn in a root of their own, outside your React tree, so what they return must not read your context: a router's `<Link>` throws there, and the block shows its Markdown under a notice instead. The stylesheet styles nothing outside `.markdown`. The faces of the default theme are Inter and Space Grotesk, which the page loads.
|
|
38
40
|
|
|
39
41
|
## Themes
|
|
40
42
|
|
|
@@ -71,12 +73,16 @@ const acme = defineTheme({
|
|
|
71
73
|
- **Your CSS** is scoped by `.markdown-theme-<name>`, and reaches the note and nothing else.
|
|
72
74
|
- **Slots** — `callout`, `calloutIcon`, `table`, `codeBlock`, `inlineCode`, `heading`, `blockquote`, `embed`, `footnotes`, `taskBox`, `wikilink`, `diagram`, `properties`, `modeSwitch` — are called with the notation already read. A slot decides how a block looks, never what it means: the links it draws go where the host resolved them, a task box reports through the `toggle` it is given, and no raw HTML ever reaches it.
|
|
73
75
|
|
|
76
|
+
A ` ```contents ` block is the note's table of contents (§7.17): its headings at the top level, nested, each a link to the heading, which carries its slug as its id, prefixed `user-content-`, and as `data-heading`, so a link written as `#deliberações` lands on it too. The block's lines set the title and the depth, `screen` and `print` groups for each medium, or `none`, and `place: start` or `end` to draw it there instead of where it is written. `contents` gives the same settings for a note with no block, and the defaults of one that has a block; with `printing` only `print` is drawn, and otherwise a drawing for one medium is marked `data-media`, which the stylesheet shows only there. Printed, each entry is a link a paginator numbers with `target-counter()`. Inside an embed a block draws nothing. A block also lists `figures:`, `tables:` and `attachments:`: an image alone in its paragraph, remote or a kept file `fileOf` says is an image; each table, a `table` block by its `title:` key and a Markdown table by a `Table: …` paragraph after it, which is drawn as its caption whatever lists it; and each kept file the note embeds. An entry is the title written, else the file's description, else its name, and where a medium lists a kind, each of its items carries a line under it with its number, in `strings.figureNumber` and `strings.tableNumber`.
|
|
77
|
+
|
|
74
78
|
The frontmatter is the note's too. The default theme draws it as MemorySmith does: `name` as the title, and the other entries in a block that folds, each key with the icon of its value's shape, lists as chips and dates in `strings.locale`, with a `[[wikilink]]`, a Markdown link or a web address in a value drawn as a link. A theme decides otherwise through the `properties` slot, which may draw nothing, as a host that shows properties elsewhere does:
|
|
75
79
|
|
|
76
80
|
```tsx
|
|
77
81
|
const mine = defineTheme({ name: 'mine', components: { properties: () => null } });
|
|
78
82
|
```
|
|
79
83
|
|
|
84
|
+
A ` ```properties ` block says how they are drawn (§7.18): `keys:` the keys and their order, the rest left out; `title:`; `fold: open` or `closed`; `place: start` or `end` to draw them there rather than where the block is written; and `screen` and `print` groups, or `none`. The name stays the title, at the top. `properties` gives the same settings for a note with no block, and the defaults of one that has a block. The slot is handed the chosen entries with `part` — `whole`, `name` or `entries` — `title` and `fold`, and a slot that draws nothing still draws nothing.
|
|
85
|
+
|
|
80
86
|
Import `structure.css` instead of `styles.css` for a theme that draws everything itself. A theme names faces; your page loads them.
|
|
81
87
|
|
|
82
88
|
## Edit
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A note's contents drawn (`SPEC.md` §7.17, #173, #175): the lists a `contents` block, or the
|
|
3
|
+
* host's settings, resolve to, in the medium the note is drawn for, and the line under a figure or
|
|
4
|
+
* a table that a list of figures or of tables leads to.
|
|
5
|
+
*
|
|
6
|
+
* Which note is drawn is a context: `NoteBody` provides the note's outline, its figures, tables and
|
|
7
|
+
* attachments, and what each of its blocks resolves to; an embed provides `embedded`, where a block
|
|
8
|
+
* draws nothing, the apparatus of navigation being the open note's alone; and with neither — a run
|
|
9
|
+
* drawn on its own — a block is the code block it is in any other reader.
|
|
10
|
+
*
|
|
11
|
+
* Printed by a host that says so (`printing`), only the print settings are drawn. Otherwise the
|
|
12
|
+
* screen's are drawn, and the print's beside them marked `data-media`, which the stylesheet shows
|
|
13
|
+
* only on paper, so a print the browser makes on its own is the print the settings declared.
|
|
14
|
+
*/
|
|
15
|
+
import { type ReactNode } from 'react';
|
|
16
|
+
import { type KeptFile } from './host.js';
|
|
17
|
+
import { type ContentsList, type ContentsPlace, type ContentsPlan } from './contents.js';
|
|
18
|
+
import type { NoteItems, OutlineHeading, OutlineNode } from './outline.js';
|
|
19
|
+
/** What each `contents` block of a note draws, by medium. */
|
|
20
|
+
export interface BlockPlans {
|
|
21
|
+
readonly screen: ContentsPlan | null;
|
|
22
|
+
readonly print: ContentsPlan | null;
|
|
23
|
+
}
|
|
24
|
+
/** In which media a note draws a list of a kind, which is where the line under its items is drawn. */
|
|
25
|
+
export type ListedIn = Readonly<Record<ContentsList, {
|
|
26
|
+
readonly screen: boolean;
|
|
27
|
+
readonly print: boolean;
|
|
28
|
+
}>>;
|
|
29
|
+
/** The note a contents is drawn in. */
|
|
30
|
+
export type ContentsScope = {
|
|
31
|
+
readonly kind: 'note';
|
|
32
|
+
readonly headings: readonly OutlineHeading[];
|
|
33
|
+
readonly items: NoteItems;
|
|
34
|
+
/** What each kept file is, as the host said, for a figure's or an attachment's description. */
|
|
35
|
+
readonly files: ReadonlyMap<string, KeptFile | null | undefined>;
|
|
36
|
+
/** What each block of the note draws, by its ordinal. */
|
|
37
|
+
readonly blocks: readonly BlockPlans[];
|
|
38
|
+
readonly listed: ListedIn;
|
|
39
|
+
readonly printing: boolean;
|
|
40
|
+
/** Whether the tables print as appendices, where a table's entry leads instead (#165). */
|
|
41
|
+
readonly appendices: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: 'embedded';
|
|
44
|
+
};
|
|
45
|
+
export declare const ContentsContext: import("react").Context<ContentsScope | null>;
|
|
46
|
+
/** The scope of an embedded note, where no contents is drawn. */
|
|
47
|
+
export declare const EMBEDDED: ContentsScope;
|
|
48
|
+
/** The media each kind is listed in, over every plan a note draws. */
|
|
49
|
+
export declare function listedIn(plans: readonly BlockPlans[]): ListedIn;
|
|
50
|
+
/**
|
|
51
|
+
* A `contents` block where it is written: what it draws here in each medium, nothing inside an
|
|
52
|
+
* embed, and its code block where no note's outline is known.
|
|
53
|
+
*/
|
|
54
|
+
export declare function ContentsBlock({ ordinal, fallback }: {
|
|
55
|
+
ordinal: number | null;
|
|
56
|
+
fallback: ReactNode;
|
|
57
|
+
}): import("react").JSX.Element | null;
|
|
58
|
+
/** The contents that resolve to `place` — `null` for where a block is written — in each medium. */
|
|
59
|
+
export declare function ContentsAt({ plans, place }: {
|
|
60
|
+
plans: BlockPlans;
|
|
61
|
+
place: ContentsPlace | null;
|
|
62
|
+
}): import("react").JSX.Element | null;
|
|
63
|
+
/** Inlines of the note, as an entry draws them. */
|
|
64
|
+
export declare function inlines(content: readonly OutlineNode[]): ReactNode;
|
|
65
|
+
/**
|
|
66
|
+
* What names a kept file or a remote image: the title written, else the file's description, else
|
|
67
|
+
* its name (#175).
|
|
68
|
+
*/
|
|
69
|
+
export declare function FileLabel({ name, title }: {
|
|
70
|
+
name: string;
|
|
71
|
+
title: string | null;
|
|
72
|
+
}): import("react").JSX.Element;
|
|
73
|
+
/**
|
|
74
|
+
* The line under a figure or a table (#175): a table's `Table:` caption, always, without its
|
|
75
|
+
* keyword; and the item's number, with a figure's label, in each medium where the note lists that
|
|
76
|
+
* kind, and nowhere else, so a note with no list draws its images and tables as before.
|
|
77
|
+
*/
|
|
78
|
+
export declare function Caption({ kind, number, children }: {
|
|
79
|
+
kind: 'figure' | 'table';
|
|
80
|
+
number: number | null;
|
|
81
|
+
children?: ReactNode;
|
|
82
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A note's contents drawn (`SPEC.md` §7.17, #173, #175): the lists a `contents` block, or the
|
|
4
|
+
* host's settings, resolve to, in the medium the note is drawn for, and the line under a figure or
|
|
5
|
+
* a table that a list of figures or of tables leads to.
|
|
6
|
+
*
|
|
7
|
+
* Which note is drawn is a context: `NoteBody` provides the note's outline, its figures, tables and
|
|
8
|
+
* attachments, and what each of its blocks resolves to; an embed provides `embedded`, where a block
|
|
9
|
+
* draws nothing, the apparatus of navigation being the open note's alone; and with neither — a run
|
|
10
|
+
* drawn on its own — a block is the code block it is in any other reader.
|
|
11
|
+
*
|
|
12
|
+
* Printed by a host that says so (`printing`), only the print settings are drawn. Otherwise the
|
|
13
|
+
* screen's are drawn, and the print's beside them marked `data-media`, which the stylesheet shows
|
|
14
|
+
* only on paper, so a print the browser makes on its own is the print the settings declared.
|
|
15
|
+
*/
|
|
16
|
+
import { createContext, useContext } from 'react';
|
|
17
|
+
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
|
|
18
|
+
import { toHast } from 'mdast-util-to-hast';
|
|
19
|
+
import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
|
|
20
|
+
import { useHost } from './host.js';
|
|
21
|
+
import { InPageAnchor } from './InPageAnchor.js';
|
|
22
|
+
import { samePlan } from './contents.js';
|
|
23
|
+
import { appendixId } from './appendices.js';
|
|
24
|
+
export const ContentsContext = createContext(null);
|
|
25
|
+
/** The scope of an embedded note, where no contents is drawn. */
|
|
26
|
+
export const EMBEDDED = { kind: 'embedded' };
|
|
27
|
+
/** The media each kind is listed in, over every plan a note draws. */
|
|
28
|
+
export function listedIn(plans) {
|
|
29
|
+
const kinds = ['headings', 'figures', 'tables', 'attachments'];
|
|
30
|
+
const has = (medium, kind) => plans.some((plan) => plan[medium]?.lists.some((list) => list.kind === kind) ?? false);
|
|
31
|
+
return Object.fromEntries(kinds.map((kind) => [kind, { screen: has('screen', kind), print: has('print', kind) }]));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A `contents` block where it is written: what it draws here in each medium, nothing inside an
|
|
35
|
+
* embed, and its code block where no note's outline is known.
|
|
36
|
+
*/
|
|
37
|
+
export function ContentsBlock({ ordinal, fallback }) {
|
|
38
|
+
const scope = useContext(ContentsContext);
|
|
39
|
+
if (scope === null)
|
|
40
|
+
return _jsx(_Fragment, { children: fallback });
|
|
41
|
+
if (scope.kind === 'embedded')
|
|
42
|
+
return null;
|
|
43
|
+
const plans = ordinal === null ? undefined : scope.blocks[ordinal];
|
|
44
|
+
if (!plans)
|
|
45
|
+
return _jsx(_Fragment, { children: fallback });
|
|
46
|
+
return _jsx(ContentsAt, { plans: plans, place: null });
|
|
47
|
+
}
|
|
48
|
+
/** The contents that resolve to `place` — `null` for where a block is written — in each medium. */
|
|
49
|
+
export function ContentsAt({ plans, place }) {
|
|
50
|
+
const scope = useContext(ContentsContext);
|
|
51
|
+
if (scope === null || scope.kind !== 'note')
|
|
52
|
+
return null;
|
|
53
|
+
const at = (plan) => (plan && plan.place === place ? plan : null);
|
|
54
|
+
if (scope.printing) {
|
|
55
|
+
const print = at(plans.print);
|
|
56
|
+
return print ? _jsx(ContentsNav, { plan: print, medium: null }) : null;
|
|
57
|
+
}
|
|
58
|
+
const screen = at(plans.screen);
|
|
59
|
+
const print = at(plans.print);
|
|
60
|
+
if (screen && print && samePlan(screen, print))
|
|
61
|
+
return _jsx(ContentsNav, { plan: screen, medium: null });
|
|
62
|
+
return (_jsxs(_Fragment, { children: [screen && _jsx(ContentsNav, { plan: screen, medium: "screen" }), print && _jsx(ContentsNav, { plan: print, medium: "print" })] }));
|
|
63
|
+
}
|
|
64
|
+
/** The headings within `depth` levels of the highest, nested under the heading above them. */
|
|
65
|
+
function branches(headings, depth) {
|
|
66
|
+
const top = Math.min(...headings.map((heading) => heading.level));
|
|
67
|
+
const roots = [];
|
|
68
|
+
const stack = [{ level: 0, children: roots }];
|
|
69
|
+
for (const heading of headings) {
|
|
70
|
+
if (heading.level >= top + depth)
|
|
71
|
+
continue;
|
|
72
|
+
while (stack.length > 1 && stack[stack.length - 1].level >= heading.level)
|
|
73
|
+
stack.pop();
|
|
74
|
+
const branch = { heading, children: [] };
|
|
75
|
+
stack[stack.length - 1].children.push(branch);
|
|
76
|
+
stack.push({ level: heading.level, children: branch.children });
|
|
77
|
+
}
|
|
78
|
+
return roots;
|
|
79
|
+
}
|
|
80
|
+
/** Inlines of the note, as an entry draws them. */
|
|
81
|
+
export function inlines(content) {
|
|
82
|
+
const tree = toHast({ type: 'paragraph', children: content });
|
|
83
|
+
const root = tree.type === 'element' ? { type: 'root', children: tree.children } : tree;
|
|
84
|
+
return toJsxRuntime(root, { Fragment, jsx, jsxs });
|
|
85
|
+
}
|
|
86
|
+
function Headings({ branches }) {
|
|
87
|
+
return (_jsx("ol", { className: "contents-entries", children: branches.map(({ heading, children }) => (_jsxs("li", { className: "contents-item", children: [_jsxs(InPageAnchor, { href: `#${heading.id}`, className: "contents-entry", children: [heading.number !== null && (_jsxs(_Fragment, { children: [_jsx("span", { className: "contents-number", children: heading.number }), ' '] })), inlines(heading.content)] }), children.length > 0 && _jsx(Headings, { branches: children })] }, heading.id))) }));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* What names a kept file or a remote image: the title written, else the file's description, else
|
|
91
|
+
* its name (#175).
|
|
92
|
+
*/
|
|
93
|
+
export function FileLabel({ name, title }) {
|
|
94
|
+
const scope = useContext(ContentsContext);
|
|
95
|
+
const file = scope?.kind === 'note' ? scope.files.get(name) : undefined;
|
|
96
|
+
return _jsx(_Fragment, { children: title || file?.description || name });
|
|
97
|
+
}
|
|
98
|
+
/** What names a table: its caption, else a block's title or table, else nothing beyond its number. */
|
|
99
|
+
function TableLabel({ table }) {
|
|
100
|
+
if (table.caption)
|
|
101
|
+
return _jsx(_Fragment, { children: inlines(table.caption) });
|
|
102
|
+
return _jsx(_Fragment, { children: table.title ?? '' });
|
|
103
|
+
}
|
|
104
|
+
function Figures({ figures }) {
|
|
105
|
+
const { strings } = useHost();
|
|
106
|
+
return (_jsx("ol", { className: "contents-entries", children: figures.map((figure) => (_jsx("li", { className: "contents-item", children: _jsxs(InPageAnchor, { href: `#${figure.id}`, className: "contents-entry", children: [_jsx("span", { className: "contents-number", children: strings.figureNumber(figure.number) }), " ", _jsx(FileLabel, { name: figure.name, title: figure.title })] }) }, figure.id))) }));
|
|
107
|
+
}
|
|
108
|
+
function Tables({ tables, appendices }) {
|
|
109
|
+
const { strings } = useHost();
|
|
110
|
+
return (_jsx("ol", { className: "contents-entries", children: tables.map((table) => (_jsx("li", { className: "contents-item", children: _jsxs(InPageAnchor, { href: `#${appendices ? appendixId(table.number) : table.id}`, className: "contents-entry", children: [_jsx("span", { className: "contents-number", children: strings.tableNumber(table.number) }), " ", _jsx(TableLabel, { table: table })] }) }, table.id))) }));
|
|
111
|
+
}
|
|
112
|
+
function Attachments({ attachments }) {
|
|
113
|
+
return (_jsx("ol", { className: "contents-entries", children: attachments.map((attachment) => (_jsx("li", { className: "contents-item", children: _jsx(InPageAnchor, { href: `#${attachment.id}`, className: "contents-entry", children: _jsx(FileLabel, { name: attachment.name, title: attachment.title }) }) }, attachment.id))) }));
|
|
114
|
+
}
|
|
115
|
+
/** One drawn contents: each of its lists under its title. */
|
|
116
|
+
function ContentsNav({ plan, medium }) {
|
|
117
|
+
const { strings } = useHost();
|
|
118
|
+
const scope = useContext(ContentsContext);
|
|
119
|
+
if (scope?.kind !== 'note')
|
|
120
|
+
return null;
|
|
121
|
+
const titles = {
|
|
122
|
+
headings: strings.contentsHeadings,
|
|
123
|
+
figures: strings.contentsFigures,
|
|
124
|
+
tables: strings.contentsTables,
|
|
125
|
+
attachments: strings.contentsAttachments,
|
|
126
|
+
};
|
|
127
|
+
// A figure is known once its file is: until then the contents is busy, and a host that prints waits.
|
|
128
|
+
const busy = scope.items.pending && plan.lists.some((list) => list.kind === 'figures');
|
|
129
|
+
return (_jsx("nav", { className: "contents", "data-media": medium ?? undefined, "aria-busy": busy || undefined, children: plan.lists.map((list) => {
|
|
130
|
+
const title = list.title ?? titles[list.kind];
|
|
131
|
+
return (_jsxs("section", { className: "contents-list", "data-list": list.kind, "aria-label": title, children: [_jsx("p", { className: "contents-title", children: title }), list.kind === 'headings' && scope.headings.length > 0 && _jsx(Headings, { branches: branches(scope.headings, list.depth) }), list.kind === 'figures' && scope.items.figures.length > 0 && _jsx(Figures, { figures: scope.items.figures }), list.kind === 'tables' && scope.items.tables.length > 0 && _jsx(Tables, { tables: scope.items.tables, appendices: scope.appendices }), list.kind === 'attachments' && scope.items.attachments.length > 0 && _jsx(Attachments, { attachments: scope.items.attachments })] }, list.kind));
|
|
132
|
+
}) }));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The line under a figure or a table (#175): a table's `Table:` caption, always, without its
|
|
136
|
+
* keyword; and the item's number, with a figure's label, in each medium where the note lists that
|
|
137
|
+
* kind, and nowhere else, so a note with no list draws its images and tables as before.
|
|
138
|
+
*/
|
|
139
|
+
export function Caption({ kind, number, children }) {
|
|
140
|
+
const scope = useContext(ContentsContext);
|
|
141
|
+
const { strings } = useHost();
|
|
142
|
+
const note = scope?.kind === 'note' ? scope : null;
|
|
143
|
+
const listed = note && number !== null ? note.listed[kind === 'figure' ? 'figures' : 'tables'] : { screen: false, print: false };
|
|
144
|
+
const media = note?.printing
|
|
145
|
+
? listed.print
|
|
146
|
+
? [null]
|
|
147
|
+
: []
|
|
148
|
+
: listed.screen && listed.print
|
|
149
|
+
? [null]
|
|
150
|
+
: [...(listed.screen ? ['screen'] : []), ...(listed.print ? ['print'] : [])];
|
|
151
|
+
const written = Array.isArray(children) ? children.length > 0 : children !== undefined && children !== null && children !== '';
|
|
152
|
+
if (kind === 'table') {
|
|
153
|
+
if (!written && media.length === 0)
|
|
154
|
+
return null;
|
|
155
|
+
const label = strings.tableNumber(number ?? 0);
|
|
156
|
+
return (_jsxs("p", { className: "table-caption", "data-media": !written && media.length === 1 && media[0] ? media[0] : undefined, children: [media.map((medium) => (_jsxs("span", { className: "caption-number", "data-media": medium ?? undefined, children: [label, written ? ' ' : ''] }, medium ?? 'all'))), children] }));
|
|
157
|
+
}
|
|
158
|
+
if (media.length === 0 || number === null || !note)
|
|
159
|
+
return null;
|
|
160
|
+
const figure = note.items.figures.find((each) => each.number === number);
|
|
161
|
+
return (_jsx(_Fragment, { children: media.map((medium) => (_jsxs("span", { className: "figure-caption", "data-media": medium ?? undefined, children: [_jsx("span", { className: "caption-number", children: strings.figureNumber(number) }), " ", figure && _jsx(FileLabel, { name: figure.name, title: figure.title })] }, medium ?? 'all'))) }));
|
|
162
|
+
}
|
package/dist/DataTable.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/**
|
|
3
3
|
* A `table` block drawn as the table it asks for (`SPEC.md` §7.15, #138).
|
|
4
4
|
*
|
|
@@ -21,6 +21,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
21
21
|
*/
|
|
22
22
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
23
23
|
import { useHost } from './host.js';
|
|
24
|
+
import { followable } from './address.js';
|
|
24
25
|
import { checkTableBlock, fold, readTableBlock, } from './table-block.js';
|
|
25
26
|
export function DataTable({ source, fallback }) {
|
|
26
27
|
const { queryTable, openTableRow, strings, printing } = useHost();
|
|
@@ -94,6 +95,15 @@ export function DataTable({ source, fallback }) {
|
|
|
94
95
|
const layout = printing ? null : layoutOf(columns, answer, totalAt, strings, widths.current);
|
|
95
96
|
// A shorter last page keeps the height of a full one, so the footer stays where it was (#163).
|
|
96
97
|
const fillers = printing || pages < 2 ? 0 : Math.max(0, block.page - answer.rows.length);
|
|
98
|
+
// The column whose cell leads where the host says its row leads (#171): the one it names, when
|
|
99
|
+
// drawn, else the first.
|
|
100
|
+
const named = answer.linkColumn ? columns.findIndex((column) => fold(column.name) === fold(answer.linkColumn)) : -1;
|
|
101
|
+
const linkAt = answer.links ? (named === -1 ? 0 : named) : -1;
|
|
102
|
+
const cellOf = (row, index, column, at) => {
|
|
103
|
+
const value = formatValue(row[column.name] ?? null, column, strings);
|
|
104
|
+
const address = at === linkAt ? (answer.links?.[index] ?? null) : null;
|
|
105
|
+
return address === null || value === '' ? value : _jsx(RowLink, { href: address, children: value });
|
|
106
|
+
};
|
|
97
107
|
const open = (row) => {
|
|
98
108
|
const view = { table: block.table ?? '', columns, row, values: columns.map((column) => formatValue(row[column.name] ?? null, column, strings)) };
|
|
99
109
|
if (openRow.current)
|
|
@@ -105,19 +115,22 @@ export function DataTable({ source, fallback }) {
|
|
|
105
115
|
const first = current[0];
|
|
106
116
|
const sorted = first !== undefined && fold(first.column) === fold(column.name) ? (first.descending ? 'descending' : 'ascending') : undefined;
|
|
107
117
|
return (_jsx("th", { "aria-sort": sorted, className: alignOf(column), children: printing ? (_jsx("span", { className: "data-table-sort", children: column.name })) : (_jsxs("button", { type: "button", className: "data-table-sort", title: strings.tableSortBy(column.name), onClick: () => sortBy(column), children: [column.name, sorted && _jsx("span", { "aria-hidden": "true", children: sorted === 'ascending' ? ' ▲' : ' ▼' })] })) }, column.name));
|
|
108
|
-
}) }) }), _jsxs("tbody", { children: [answer.rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { className: "data-table-empty", colSpan: columns.length, children: strings.tableEmpty }) })) : (answer.rows.map((row, index) => printing ? (_jsx("tr", { children: columns.map((column) => (_jsx("td", { className: alignOf(column), children:
|
|
118
|
+
}) }) }), _jsxs("tbody", { children: [answer.rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { className: "data-table-empty", colSpan: columns.length, children: strings.tableEmpty }) })) : (answer.rows.map((row, index) => printing ? (_jsx("tr", { children: columns.map((column, at) => (_jsx("td", { className: alignOf(column), children: cellOf(row, index, column, at) }, column.name))) }, index)) : (_jsx("tr", { className: "data-table-row", tabIndex: 0, onClick: (event) => {
|
|
109
119
|
// Text the reader selected in a cell is theirs to copy, and opens nothing.
|
|
110
120
|
if (!window.getSelection?.()?.isCollapsed && window.getSelection()?.toString())
|
|
111
121
|
return;
|
|
122
|
+
// A link in a cell is followed, and opens no dialog (#171).
|
|
123
|
+
if (event.target.closest?.('a'))
|
|
124
|
+
return;
|
|
112
125
|
open(row);
|
|
113
126
|
}, onKeyDown: (event) => {
|
|
114
127
|
if (event.key !== 'Enter' || event.target !== event.currentTarget)
|
|
115
128
|
return;
|
|
116
129
|
event.preventDefault();
|
|
117
130
|
open(row);
|
|
118
|
-
}, children: columns.map((column) => {
|
|
131
|
+
}, children: columns.map((column, at) => {
|
|
119
132
|
const value = formatValue(row[column.name] ?? null, column, strings);
|
|
120
|
-
return (_jsx("td", { className: alignOf(column), title: value || undefined, children:
|
|
133
|
+
return (_jsx("td", { className: alignOf(column), title: value || undefined, children: cellOf(row, index, column, at) }, column.name));
|
|
121
134
|
}) }, index)))), Array.from({ length: fillers }, (_, index) => (_jsx("tr", { className: "data-table-filler", "aria-hidden": "true", children: _jsx("td", { colSpan: columns.length, children: '\u00a0' }) }, `filler-${index}`)))] }), totalAt !== -1 && answer.total !== null && (_jsx("tfoot", { children: _jsx("tr", { children: columns.map((column, index) => (_jsx("td", { className: alignOf(column), children: index === totalAt ? formatNumber(answer.total, strings.locale) : index === 0 ? strings.tableTotal : null }, column.name))) }) }))] }) }), printing ? (_jsx("p", { className: "data-table-printed", children: strings.tablePrinted({ table: block.table ?? '', filter: block.whereText, count: answer.count, readAt: formatDate(answer.readAt, strings.locale) ?? answer.readAt }) })) : (_jsxs("div", { className: "data-table-footer", children: [_jsx("span", { className: "data-table-count", children: strings.tableShowing(answer.count === 0 ? 0 : (shown - 1) * block.page + 1, Math.min(shown * block.page, answer.count), answer.count) }), pages > 1 && (_jsxs("span", { className: "data-table-pages", children: [_jsxs("button", { type: "button", className: "data-table-page", disabled: shown <= 1, onClick: () => setPage(shown - 1), title: strings.tablePrevious, children: [_jsx("span", { className: "data-table-page-arrow", "aria-hidden": "true", children: "\u2039" }), _jsx("span", { className: "data-table-page-word", children: strings.tablePrevious })] }), _jsxs("button", { type: "button", className: "data-table-page", disabled: shown >= pages, onClick: () => setPage(shown + 1), title: strings.tableNext, children: [_jsx("span", { className: "data-table-page-word", children: strings.tableNext }), _jsx("span", { className: "data-table-page-arrow", "aria-hidden": "true", children: "\u203A" })] })] }))] })), opened && _jsx(RowDialog, { view: opened, onClose: () => setOpened(null) })] }));
|
|
122
135
|
}
|
|
123
136
|
/**
|
|
@@ -125,6 +138,20 @@ export function DataTable({ source, fallback }) {
|
|
|
125
138
|
* column's name and its value as the table draws it, wrapping as long as it needs. Escape, the
|
|
126
139
|
* button and a click outside it close it.
|
|
127
140
|
*/
|
|
141
|
+
/**
|
|
142
|
+
* A cell that leads where the host says its row leads (#171), drawn as a link of the note is: an
|
|
143
|
+
* address of the host's own through its `renderLink`, another one, the address filter letting it
|
|
144
|
+
* through, as a link to the web, and one it refuses as text.
|
|
145
|
+
*/
|
|
146
|
+
function RowLink({ href, children }) {
|
|
147
|
+
const host = useHost();
|
|
148
|
+
const address = followable(href);
|
|
149
|
+
if (!address)
|
|
150
|
+
return _jsx(_Fragment, { children: children });
|
|
151
|
+
if (address.startsWith('/'))
|
|
152
|
+
return _jsx(_Fragment, { children: host.renderLink({ href: address, className: 'data-table-link', children }) });
|
|
153
|
+
return (_jsx("a", { className: "data-table-link", href: address, target: "_blank", rel: "noreferrer", children: children }));
|
|
154
|
+
}
|
|
128
155
|
function RowDialog({ view, onClose }) {
|
|
129
156
|
const { strings } = useHost();
|
|
130
157
|
const dialog = useRef(null);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnchorHTMLAttributes } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A link to a place in the same note: a footnote and its way back (§7.12), an entry of a contents
|
|
4
|
+
* (§7.17), or an anchor an author wrote.
|
|
5
|
+
*
|
|
6
|
+
* It must not open the whole page in another tab, and a bare hash is not enough either: a host may
|
|
7
|
+
* scroll the note inside a pane of its own rather than the window, and an embedded note renders the
|
|
8
|
+
* same identifiers a second time. So the target is looked up inside the note the link was drawn in,
|
|
9
|
+
* and brought into view in whatever scrolls it; the address of the page does not change, because
|
|
10
|
+
* nothing was navigated.
|
|
11
|
+
*
|
|
12
|
+
* The target is the element of that id, else the heading whose slug it is (`data-heading`): an
|
|
13
|
+
* author writes `#the-section`, and a heading of the note carries it as its id with a prefix,
|
|
14
|
+
* while a heading inside an embed carries no id at all (#173).
|
|
15
|
+
*/
|
|
16
|
+
export declare function InPageAnchor({ href, children, ...rest }: AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
17
|
+
href: string;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
19
|
+
/** The element a link to `#id` drawn at `link` lands on, in the note or the embed it is drawn in. */
|
|
20
|
+
export declare function inPageTarget(link: Element, href: string): HTMLElement | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A link to a place in the same note: a footnote and its way back (§7.12), an entry of a contents
|
|
4
|
+
* (§7.17), or an anchor an author wrote.
|
|
5
|
+
*
|
|
6
|
+
* It must not open the whole page in another tab, and a bare hash is not enough either: a host may
|
|
7
|
+
* scroll the note inside a pane of its own rather than the window, and an embedded note renders the
|
|
8
|
+
* same identifiers a second time. So the target is looked up inside the note the link was drawn in,
|
|
9
|
+
* and brought into view in whatever scrolls it; the address of the page does not change, because
|
|
10
|
+
* nothing was navigated.
|
|
11
|
+
*
|
|
12
|
+
* The target is the element of that id, else the heading whose slug it is (`data-heading`): an
|
|
13
|
+
* author writes `#the-section`, and a heading of the note carries it as its id with a prefix,
|
|
14
|
+
* while a heading inside an embed carries no id at all (#173).
|
|
15
|
+
*/
|
|
16
|
+
export function InPageAnchor({ href, children, ...rest }) {
|
|
17
|
+
const follow = (event) => {
|
|
18
|
+
const target = inPageTarget(event.currentTarget, href);
|
|
19
|
+
if (!target)
|
|
20
|
+
return;
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
target.scrollIntoView({ block: 'center' });
|
|
23
|
+
};
|
|
24
|
+
return (_jsx("a", { href: href, onClick: follow, ...rest, children: children }));
|
|
25
|
+
}
|
|
26
|
+
/** The element a link to `#id` drawn at `link` lands on, in the note or the embed it is drawn in. */
|
|
27
|
+
export function inPageTarget(link, href) {
|
|
28
|
+
const id = decodeURIComponent(href.slice(1));
|
|
29
|
+
// The note is the root `NoteBody` draws, since a footnote's way back may cross runs; inside an
|
|
30
|
+
// embed it is the embed's own run. A match inside an embed answers only a link inside that same embed.
|
|
31
|
+
const embed = link.closest('.embed');
|
|
32
|
+
const note = embed ? link.closest('.markdown') : (link.closest('.markdown[data-theme]') ?? link.closest('.markdown'));
|
|
33
|
+
const within = (selector) => [...(note?.querySelectorAll(selector) ?? [])].find((candidate) => candidate.closest('.embed') === embed) ?? null;
|
|
34
|
+
return within(`[id="${CSS.escape(id)}"]`) ?? within(`[data-heading="${CSS.escape(id)}"]`);
|
|
35
|
+
}
|
package/dist/Markdown.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type TableAppendix } from './appendices.js';
|
|
|
3
3
|
import { type StyleRange } from './style-block.js';
|
|
4
4
|
import { type FootnoteRef } from './footnotes.js';
|
|
5
5
|
import type { TaskSave } from './task-saves.js';
|
|
6
|
+
import { type OutlineRun } from './outline.js';
|
|
6
7
|
/**
|
|
7
8
|
* One run of a note, parsed and drawn: the pipeline of MemorySmith's reading page.
|
|
8
9
|
*
|
|
@@ -46,6 +47,11 @@ export interface MarkdownProps {
|
|
|
46
47
|
* note, which is drawn on its own.
|
|
47
48
|
*/
|
|
48
49
|
readonly styles?: readonly StyleRange[];
|
|
50
|
+
/**
|
|
51
|
+
* The slugs of this run's headings and the ordinal of its first `contents` block, counted over
|
|
52
|
+
* the whole note (`outline.ts`, #173). Left out, the run counts its own: a note drawn in one run.
|
|
53
|
+
*/
|
|
54
|
+
readonly outline?: OutlineRun;
|
|
49
55
|
}
|
|
50
56
|
/**
|
|
51
57
|
* What react-markdown hands a component beside the attributes: the hast
|
|
@@ -68,5 +74,5 @@ type WithNode<T> = T & {
|
|
|
68
74
|
*/
|
|
69
75
|
export declare function MarkdownImage({ alt, node: _node, ...rest }: WithNode<ImgHTMLAttributes<HTMLImageElement>>): import("react").JSX.Element;
|
|
70
76
|
export declare function MarkdownAnchor({ href, children, node: _node, ...rest }: WithNode<AnchorHTMLAttributes<HTMLAnchorElement>>): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
|
|
71
|
-
export declare function Markdown({ children, source, onToggleTask, taskSave, writable, footnotes, appendices, styles }: MarkdownProps): import("react").JSX.Element;
|
|
77
|
+
export declare function Markdown({ children, source, onToggleTask, taskSave, writable, footnotes, appendices, styles, outline }: MarkdownProps): import("react").JSX.Element;
|
|
72
78
|
export {};
|
package/dist/Markdown.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
|
|
3
|
-
import { isValidElement, useEffect, useMemo, useReducer, useState, } from 'react';
|
|
3
|
+
import { isValidElement, useContext, useEffect, useMemo, useReducer, useState, } from 'react';
|
|
4
4
|
import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
|
|
5
5
|
import ReactMarkdown from 'react-markdown';
|
|
6
6
|
import rehypeKatex from 'rehype-katex';
|
|
@@ -23,6 +23,13 @@ import { findStyleBlocks, rangesFor, remarkStyleBlocks } from './style-block.js'
|
|
|
23
23
|
import { CLOBBER_PREFIX, rehypeFootnoteRun, rehypeFootnoteSection } from './footnotes.js';
|
|
24
24
|
import { drawSlot, headings, InBlock, MarkdownBlockquote, MarkdownDiv, MarkdownSection, MarkdownTable, useInBlock, useSlot } from './slots.js';
|
|
25
25
|
import { ordinalAt } from './tasklist.js';
|
|
26
|
+
import { InPageAnchor } from './InPageAnchor.js';
|
|
27
|
+
import { Caption, ContentsBlock, ContentsContext } from './ContentsBlock.js';
|
|
28
|
+
import { isPropertiesBlock } from './properties-block.js';
|
|
29
|
+
import { PropertiesBlockAt } from './PropertiesBlock.js';
|
|
30
|
+
import { tableId } from './outline.js';
|
|
31
|
+
import { isContentsBlock } from './contents.js';
|
|
32
|
+
import { remarkOutline } from './outline.js';
|
|
26
33
|
/**
|
|
27
34
|
* An image, with the dimensions the specification puts in its alt text
|
|
28
35
|
* (§3.14). What precedes the pipe is the description and is never dropped;
|
|
@@ -42,34 +49,6 @@ export function MarkdownImage({ alt, node: _node, ...rest }) {
|
|
|
42
49
|
const title = rest.title || read.description || undefined;
|
|
43
50
|
return _jsx("img", { ...rest, alt: read.description, title: title, ...sizedAttributes(read) });
|
|
44
51
|
}
|
|
45
|
-
/**
|
|
46
|
-
* A link to a place in the same note: a footnote and its way back (§7.12),
|
|
47
|
-
* or an anchor an author wrote.
|
|
48
|
-
*
|
|
49
|
-
* It must not open the whole page in another tab, and a bare hash is not
|
|
50
|
-
* enough either: a host may scroll the note inside a pane of its own rather
|
|
51
|
-
* than the window, and an embedded note renders the same identifiers a second
|
|
52
|
-
* time. So the target is looked up inside the note the link was drawn in, and
|
|
53
|
-
* brought into view in whatever scrolls it; the address of the page does not
|
|
54
|
-
* change, because nothing was navigated.
|
|
55
|
-
*/
|
|
56
|
-
function InPageAnchor({ href, children, ...rest }) {
|
|
57
|
-
const follow = (event) => {
|
|
58
|
-
const id = decodeURIComponent(href.slice(1));
|
|
59
|
-
// The note is the root `NoteBody` draws, since a footnote's way back may
|
|
60
|
-
// cross runs; inside an embed it is the embed's own run. A match inside
|
|
61
|
-
// an embed answers only a link inside that same embed.
|
|
62
|
-
const link = event.currentTarget;
|
|
63
|
-
const embed = link.closest('.embed');
|
|
64
|
-
const note = embed ? link.closest('.markdown') : (link.closest('.markdown[data-theme]') ?? link.closest('.markdown'));
|
|
65
|
-
const target = [...(note?.querySelectorAll(`[id="${CSS.escape(id)}"]`) ?? [])].find((candidate) => candidate.closest('.embed') === embed);
|
|
66
|
-
if (!(target instanceof HTMLElement))
|
|
67
|
-
return;
|
|
68
|
-
event.preventDefault();
|
|
69
|
-
target.scrollIntoView({ block: 'center' });
|
|
70
|
-
};
|
|
71
|
-
return (_jsx("a", { href: href, onClick: follow, ...rest, children: children }));
|
|
72
|
-
}
|
|
73
52
|
function Attachment({ name, size, ...written }) {
|
|
74
53
|
const host = useHost();
|
|
75
54
|
if (!host.keeps(name))
|
|
@@ -309,10 +288,30 @@ function MarkdownPre({ children, node, ...rest }) {
|
|
|
309
288
|
// code block it is everywhere else (§7.15).
|
|
310
289
|
const meta = code?.data?.meta;
|
|
311
290
|
if (queryTable && isTableBlock(language, typeof meta === 'string' ? meta : null)) {
|
|
312
|
-
|
|
291
|
+
// Numbered among the note's tables (#175): its id, which a contents leads to, and the line under it.
|
|
292
|
+
const number = code?.properties?.['dataTable'];
|
|
293
|
+
if (typeof number !== 'number')
|
|
294
|
+
return _jsx(DataTable, { source: typed, fallback: drawn });
|
|
295
|
+
return (_jsxs("div", { id: tableId(number), className: "table-block-figure", children: [_jsx(DataTable, { source: typed, fallback: drawn }), _jsx(Caption, { kind: "table", number: number })] }));
|
|
296
|
+
}
|
|
297
|
+
// A `properties` block draws the note's properties where it is written, as it says (§7.18, #172).
|
|
298
|
+
if (isPropertiesBlock(language, typeof meta === 'string' ? meta : null)) {
|
|
299
|
+
const ordinal = code?.properties?.['dataProperties'];
|
|
300
|
+
return _jsx(PropertiesBlockAt, { ordinal: typeof ordinal === 'number' ? ordinal : null, fallback: drawn });
|
|
301
|
+
}
|
|
302
|
+
// A `contents` block is the note's contents where the note's outline is known (§7.17, #173).
|
|
303
|
+
if (isContentsBlock(language, typeof meta === 'string' ? meta : null)) {
|
|
304
|
+
const ordinal = code?.properties?.['dataContents'];
|
|
305
|
+
return _jsx(ContentsBlock, { ordinal: typeof ordinal === 'number' ? ordinal : null, fallback: drawn });
|
|
313
306
|
}
|
|
314
307
|
return drawn;
|
|
315
308
|
}
|
|
309
|
+
/** The line under a figure or a table, as `remarkOutline` marks it (#175). */
|
|
310
|
+
function MarkdownCaption({ children, node: _node, ...rest }) {
|
|
311
|
+
const attributes = rest;
|
|
312
|
+
const number = Number(attributes['data-number']);
|
|
313
|
+
return (_jsx(Caption, { kind: attributes['data-kind'] === 'table' ? 'table' : 'figure', number: Number.isFinite(number) ? number : null, children: children }));
|
|
314
|
+
}
|
|
316
315
|
/** The text of a hast element, which for a fence is the code as typed. */
|
|
317
316
|
function textOf(node) {
|
|
318
317
|
if (!node)
|
|
@@ -380,9 +379,11 @@ function dropBox(children) {
|
|
|
380
379
|
return children;
|
|
381
380
|
return children.filter((child) => !(isValidElement(child) && child.type === 'input'));
|
|
382
381
|
}
|
|
383
|
-
export function Markdown({ children, source, onToggleTask, taskSave, writable = false, footnotes, appendices, styles }) {
|
|
382
|
+
export function Markdown({ children, source, onToggleTask, taskSave, writable = false, footnotes, appendices, styles, outline }) {
|
|
384
383
|
const text = toUnixNewlines(children);
|
|
385
384
|
const { strings, queryTable } = useHost();
|
|
385
|
+
// Inside an embed a heading carries its slug and no id, so it never takes one of the note's (#173).
|
|
386
|
+
const embedded = useContext(ContentsContext)?.kind === 'embedded';
|
|
386
387
|
const calloutTitle = (kind) => Object.hasOwn(strings.callouts, kind) ? strings.callouts[kind] : undefined;
|
|
387
388
|
// A style block's fences and options leave the text, every offset kept, and its lines are wrapped once parsed (§7.16).
|
|
388
389
|
const styled = useMemo(() => {
|
|
@@ -400,6 +401,20 @@ export function Markdown({ children, source, onToggleTask, taskSave, writable =
|
|
|
400
401
|
...readingPlugins(calloutTitle, strings.parameter),
|
|
401
402
|
[remarkJustifiedColumns, { columns: justified.columns }],
|
|
402
403
|
[remarkStyleBlocks, { ranges: styled.ranges, locale: strings.locale }],
|
|
404
|
+
[
|
|
405
|
+
remarkOutline,
|
|
406
|
+
{
|
|
407
|
+
slugs: outline?.slugs ?? null,
|
|
408
|
+
numbers: outline?.numbers ?? null,
|
|
409
|
+
firstBlock: outline?.firstBlock ?? 0,
|
|
410
|
+
firstProperties: outline?.firstProperties ?? 0,
|
|
411
|
+
ids: !embedded,
|
|
412
|
+
figures: outline?.figures ?? null,
|
|
413
|
+
tables: outline?.tables ?? null,
|
|
414
|
+
attachments: outline?.attachments ?? null,
|
|
415
|
+
tableBlocks: outline?.tableBlocks ?? queryTable !== null,
|
|
416
|
+
},
|
|
417
|
+
],
|
|
403
418
|
...(appendices ? [[remarkTableReferences, { ...appendices, blocks: queryTable !== null, words: strings.tableAppendixReference }]] : []),
|
|
404
419
|
],
|
|
405
420
|
// Raw HTML is NOT enabled, and its absence is the point: no
|
|
@@ -438,6 +453,8 @@ export function Markdown({ children, source, onToggleTask, taskSave, writable =
|
|
|
438
453
|
blockquote: MarkdownBlockquote,
|
|
439
454
|
section: MarkdownSection,
|
|
440
455
|
...headings,
|
|
456
|
+
// The line under a figure or a table (#175), which `remarkOutline` puts in its place.
|
|
457
|
+
...{ 'ms-caption': MarkdownCaption },
|
|
441
458
|
li: (props) => (_jsx(TaskItem, { ...props, source: source ?? text, toggleTask: onToggleTask, taskSave: taskSave, writable: writable })),
|
|
442
459
|
}, children: justified.text }) }));
|
|
443
460
|
}
|